import time,json
import requests as rq

session = rq.session()
loginUrl = "https://xxcapp.xidian.edu.cn/uc/wap/login/check"
indexUrl = "https://xxcapp.xidian.edu.cn/ncov/wap/default/index"
submitUrl = "https://xxcapp.xidian.edu.cn/ncov/wap/default/save"
notifyUrl = "" # 请在此处填上你的server酱链接

def submit(result,userdata,submitData):
    session = rq.session()
    response = session.post(loginUrl, data=userdata)
    if response.status_code == 200:
        response = session.get(indexUrl)
        response = session.post(submitUrl, data=submitData)
        returnCode = response.json().get("e")
        if (returnCode in [0,1] or returnCode in ['0','1']):
            result.append(0)
        else:
            result.append(1)
    else: 
        time.sleep(3)
        submit(result,userdata,submitData)

userdata = {
    "username": "",
    "password": ""
}

submitData_home = {
    "szgjcs": "",
    "szcs": "",
    "szgj": "",
    "zgfxdq":"0",
    "mjry":"0",
    "csmjry":"0",
    "tw": "2",
    "sfcxtz": "0",
    "sfjcbh": "0",
    "sfcxzysx": "0",
    "qksm": "",
    "sfyyjc": "0",
    "jcjgqr": "0",
    "remark": "",
    "address": "",
    "geo_api_info": '',
    "area": "",
    "province": "",
    "city": "",
    "sfzx": "0",
    "sfjcwhry": "0",
    "sfjchbry": "0",
    "sfcyglq": "0",
    "gllx": "",
    "glksrq": "",
    "jcbhlx": "",
    "jcbhrq": "",
    "ismoved": "0",
    "bztcyy": "",
    "sftjhb": "0",
    "sftjwh": "0",
    "sfjcjwry": "0",
    "jcjg": ""
}

def run(user,result):
    for i in range(len(user)):
        userdata["username"]=user[i][0]
        userdata["password"]=user[i][1]
        submitData_home["address"]=user[i][2]
        submitData_home["geo_api_info"]=user[i][3]
        submitData_home["area"]=user[i][4]
        submitData_home["province"]=user[i][5]
        submitData_home["city"]=user[i][6]

        submit(result,userdata,submitData_home)
    return result
    

def notify(result):
    string  = ""
    for i in range(len(result)):

        if result[i] == 1:
            string = ",".join([string,user[i][2]])
            
    if len(string) != 0:
        string = "".join([string,"签到出现问题！"])[1:]
    else:
        string = "".join([string,"签到成功！"])
    # print(string)
    notifydata = {
        "text" : string,
        "desp" : "疫情通"
    }
    rq.post(notifyUrl,data = notifydata)

if __name__ == "__main__":
    user = []
    result = []
    address = ""
    geo_api_info = ''
    area = ""
    province=""
    city = ""
    temp = ["学号","教务处密码",address,geo_api_info,area,province,city]

    user.append(temp)
    notify(run(user,result))
